/*
Copyright (C) 2022-2024 Inspur Corp. All Rights Reserved.

SPDX-License-Identifier: Apache-2.0
*/
package controller

import (
	"testing"
)

func TestDidController_CheckCRUDPatten(t *testing.T) {
	testCase := []struct {
		input string
		want  bool
	}{
		{input: "", want: false},
		{input: "CRUD", want: true},
		{input: "C", want: true},
		{input: "CD", want: true},
		{input: "CUD", want: true},
		{input: "CYD", want: false},
	}
	for _, tc := range testCase {
		if ok := checkCRUDPatten(tc.input); ok != tc.want {
			t.Fatalf("check patten fail, input %s, want %v, output %v",
				tc.input, tc.want, ok)
		}
	}
}

func TestDidController_MatchCRUDPatten(t *testing.T) {
	testCase := []struct {
		match  string
		patten string
		want   bool
	}{
		{match: "CRUD", patten: "CU", want: true},
		{match: "CRUD", patten: "UD", want: true},
		{match: "CD", patten: "UD", want: false},
		{match: "", patten: "UD", want: false},
		{match: "CD", patten: "", want: false},
	}
	for _, tc := range testCase {
		if ok := matchCRUDPatten(tc.match, tc.patten); ok != tc.want {
			t.Fatalf("check patten fail, match %s, patten %s, want %v, output %v",
				tc.match, tc.patten, tc.want, ok)
		}
	}
}
